# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: Miloš Komarčević <miloskomarcevic@aim.com>

_realname=lcms2
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=2.15
pkgrel=4
pkgdesc="Small-footprint color management engine, version 2 (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url="https://www.littlecms.com/"
license=('spdx:MIT' 'spdx:GPL-3.0-or-later')
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-cc"
  "${MINGW_PACKAGE_PREFIX}-meson"
  "${MINGW_PACKAGE_PREFIX}-ninja"
  "${MINGW_PACKAGE_PREFIX}-pkgconf"
)
depends=(
  "${MINGW_PACKAGE_PREFIX}-libjpeg-turbo"
  "${MINGW_PACKAGE_PREFIX}-libtiff"
)
source=("https://downloads.sourceforge.net/sourceforge/lcms/${_realname}-${pkgver}.tar.gz"
        "https://patch-diff.githubusercontent.com/raw/mm2/Little-CMS/pull/361.patch"
        0001-disable-def-exports.patch)
sha256sums=('b20cbcbd0f503433be2a4e81462106fa61050a35074dc24a4e356792d971ab39'
            'f65f01fd9688c79ec3785b017633f98343f8bd0c5f2f59905d3f32c77ff06556'
            'aeb975c24cd3ea7f046e7167c0965271b2fc49bf540443189560db5fe427a92f')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}

  patch -Np1 -i "${srcdir}/361.patch"
  # https://github.com/mm2/Little-CMS/commit/8769c0e85b0e57de3f55936344766873fa982350
  patch -Np1 -i "${srcdir}/0001-disable-def-exports.patch"
}

build() {
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    meson setup \
      --prefix="${MINGW_PREFIX}" \
      --wrap-mode=nodownload \
      --auto-features=enabled \
      --buildtype=plain \
      -Ddefault_library=both \
      -Dfastfloat=true \
      ../${_realname}-${pkgver}

  meson compile
}

package() {
  cd "${srcdir}"/build-${MSYSTEM}

  DESTDIR="${pkgdir}" meson install

  install -Dm644 "${srcdir}"/${_realname}-${pkgver}/COPYING "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/COPYING
  install -Dm644 "${srcdir}"/${_realname}-${pkgver}/plugins/fast_float/COPYING.GPL3 "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/COPYING-fast_float
}
